package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyzy.domain.TCollect;
import com.cyzy.domain.TOrders;
import com.cyzy.dto.ResponseData;
import com.cyzy.service.TOrdersService;
import com.cyzy.mapper.TOrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
* @author 10204
* @description 针对表【t_orders(订单表，用于存储用户的订单信息)】的数据库操作Service实现
* @createDate 2024-11-28 15:20:41
*/
@Service
public class TOrdersServiceImpl extends ServiceImpl<TOrdersMapper, TOrders> implements TOrdersService{
@Autowired
    private TOrdersMapper tOrdersMapper;

    @Override
    public ResponseData setTOrders(TOrders tOrders) {
        QueryWrapper<TOrders> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("orders_id",tOrders.getOrdersId());
             TOrders orders = tOrdersMapper.selectOne(queryWrapper);
            if(orders==null){
                String uuid = UUID.randomUUID().toString();
                tOrders.setOrdersId(uuid);
                tOrdersMapper.insert(tOrders);

                return ResponseData.ok2(tOrders);
            }else{
                return ResponseData.ok2("订单已创建");
            }

    }

    @Override
    public int updataTOrders(TOrders tOrders) {
        QueryWrapper<TOrders> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("orders_id",tOrders.getOrdersId());
        TOrders existingCollect = tOrdersMapper.selectOne(queryWrapper);
          if (existingCollect != null) {
              return tOrdersMapper.updateById(tOrders);
          }
        return 0;
    }
}




